package com.chj.comp.service.demo1.controller;

import java.util.List;
import java.util.Map;
import com.chj.comp.common.core.util.PageParam;
import com.chj.comp.common.core.util.Result;
import com.chj.comp.common.core.util.SecurityUtil;
import com.chj.comp.service.demo1.entity.Demo1SchedulerJob;
import com.chj.comp.service.demo1.service.IDemo1SchedulerJobService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cuihui
 * @since 2022-02-15
 */
@RestController
@RequestMapping("/demo1SchedulerJob")
@Api(tags = "Demo1SchedulerJob接口")
@Slf4j
public class Demo1SchedulerJobController {

    @Autowired
    private IDemo1SchedulerJobService demo1SchedulerJobService;

    /**
     * 通过ID查询
     *
     * @param id ID
     * @return Result<Demo1SchedulerJob>
     *
     * @Cacheable Spring自带的缓存，因集成了redis，缓存会保存到redis，
     * 还有其他注解进行删除、修改操作，使用方便但不灵活，不推荐使用
     */
    @GetMapping("/getDemo1SchedulerJobDetail/{id}")
    @ApiOperation(value = "demo1详情(验证解密、验证Spring Cacheable)")
//    @Cacheable(value = "test", key = "#id", unless = "#result == null")
    public Result<Demo1SchedulerJob> getDemo1SchedulerJobDetail(@ApiParam(value = "id", required = true) @PathVariable String id) {
        try {
            log.info("getClientId----->" + SecurityUtil.getClientId());
            log.info("getUserId----->" + SecurityUtil.getUserId() + "");
            log.info("getUserName----->" + SecurityUtil.getUserName());
            log.info("getFullName----->" + SecurityUtil.getFullName());
            log.info("getRoles----->" + SecurityUtil.getRoles());
            return Result.ok(demo1SchedulerJobService.getById(id));
        } catch (Exception e) {
            log.error(e.getMessage());
            return  Result.failed(e.getMessage());
        }
    }

    /**
     * 分页查询信息
     *
     * @param params 查询条件
     * @return Result<Page>
     */
    @PostMapping("/getDemo1SchedulerJobList")
    @ApiOperation(value = "demo1列表(验证分页)")
    public Result<Page> getDemo1SchedulerJobList(@ApiParam(value = "params", required = true) @RequestBody Map<String, Object> params) {
        try {
            Page<Demo1SchedulerJob> page = demo1SchedulerJobService.getDemo1SchedulerJobList(new PageParam(params));
            return Result.ok(page);
        } catch (Exception e) {
            return  Result.failed(e.getMessage());
        }
    }

    /**
     * 保存数据
     *
     * @param demo1SchedulerJob
     * @return
     */
    @PostMapping("/saveDemo1SchedulerJob")
    @ApiOperation(value = "demo1保存数据(验证加密)")
    public Result saveDemo1SchedulerJob(@RequestBody Demo1SchedulerJob demo1SchedulerJob) {
        try {
            demo1SchedulerJobService.saveOrUpdate(demo1SchedulerJob);
            return Result.ok("保存成功");
        } catch (Exception e) {
            return  Result.failed(e.getMessage());
        }
    }
}
